package com.woniuxy.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.Exam;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.ExamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (Exam)表控制层
 *
 * @author zjx
 * @since 2021-05-14 19:42:02
 */
@Api(value="考试接口",description = "用于对考试实现CRUD")
@RestController
@RequestMapping("exam")
public class ExamController {
    /**
     * 服务对象
     */
    @Resource
    private ExamService examService;

    @ApiOperation("该场考试学员试卷批阅情况分页展示")
    @PostMapping("queryReview")
    public ResponseEntity queryReview(@ApiParam("起始页")Integer startPage,
                                      @ApiParam("每页条数")Integer pageSize,
                                      @ApiParam("考试id")Integer examId,
                                      @ApiParam("学员姓名")String studentName,
                                      @ApiParam("批阅状态")Integer reviewStatus){
        PageInfo<Map<String,String>> pageInfo = this.examService.queryReview(startPage,pageSize,examId,studentName,reviewStatus);
        return new ResponseEntity(200,"OK",pageInfo);

    }

    /**
     * Description : 补考记录学员分页展示
     * ChangeLog : 1. 创建 (2021/5/19 14:32 [zjx]);
     * @param startPage 起始页
     * @param pageSize 每页条数
     * @param id 补考科目id
     * @param studentName 学员姓名
     * @return null
    */
    @ApiOperation("补考记录学员分页展示")
    @PostMapping("queryMakeUpStudent")
    public ResponseEntity queryMakeUpStudent(@ApiParam("起始页")Integer startPage,
                                             @ApiParam("每页条数")Integer pageSize,
                                             @ApiParam("补考科目id")Integer id,
                                             @ApiParam("学员姓名")String studentName){
        PageInfo<Map<String,String>> pageInfo = this.examService.queryMakeUpStudent(startPage,pageSize,id,studentName);
        return new ResponseEntity(200,"OK",pageInfo);
    }
    /**
     * Description : 补考信息分页展示
     * ChangeLog : 1. 创建 (2021/5/19 9:28 [zjx]);
     * @param startPage 起始页
     * @param pageSize 每页条数
     * @param id 补考科目id
     * @return null
    */
    @ApiOperation("补考信息分页展示")
    @PostMapping("queryMakeUpAll")
    public ResponseEntity queryMakeUpAll(@ApiParam("起始页")Integer startPage,
                                         @ApiParam("每页条数")Integer pageSize,
                                         @ApiParam("补考科目id")Integer id){
        PageInfo<Map<String,String>> pageInfo = this.examService.queryMakeUpAll(startPage,pageSize,id);
        return new ResponseEntity(200,"OK",pageInfo);
    }

    /**
     * Description : 该次考试所有学员情况分页展示
     * ChangeLog : 1. 创建 (2021/5/19 9:28 [zjx]);
     * @param map
     * 起始页，每页页数
     * 考试id
     * 学员姓名
     * 考试状态
     * @return null
    */
    @ApiOperation("该次考试所有学员情况分页展示")
    @PostMapping("queryAllStudents")
    public ResponseEntity queryAllStudents(@ApiParam("起始页，每页条数，模糊查询对象")@RequestBody Map<String,Object> map ){
        PageInfo<Map<String,String>> pageInfo  = this.examService.queryAllStudents(map);
        return new ResponseEntity(200,"OK",pageInfo);
    }

    /**
     * Description : 考试管理首页分页展示
     * ChangeLog : 1. 创建 (2021/5/19 14:17 [zjx]);
     * @param startPage 起始页
     * @param pageSize 每页条数
     * @param exam 模糊查询实体
     * @return null
    */
    @ApiOperation("分页展示")
    @PostMapping("queryAll")
    public ResponseEntity queryAll(@ApiParam("起始页")Integer startPage,
                                   @ApiParam("每页条数")Integer pageSize,
                                   @ApiParam("考试实体类")Exam exam){
        System.out.println("startPage："+startPage+"pageSize："+pageSize);
        PageInfo<Map<String,String>> pageInfo =  this.examService.queryAll(startPage,pageSize,exam);
        return new ResponseEntity(200,"OK",pageInfo);
    }
    /**
     * Description : 添加一场考试，包含统一考，自由考，补考等
     * ChangeLog : 1. 创建 (2021/5/18 14:24 [zjx]);
     * @param exam 考试实体类
     * @return null
    */
    @PostMapping("insert")
    @ApiOperation("添加一场考试")
    public ResponseEntity insert(@ApiParam("考试实体类") Exam exam){
        Exam insert = this.examService.insert(exam);
        return new ResponseEntity(200,"OK",insert);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("用id查询一个")
    @GetMapping("selectOne")
    public ResponseEntity selectOne(@ApiParam("考试id") Integer id) {
        return new ResponseEntity(200,"OK",this.examService.queryById(id));
    }

    /**
     * Description : 通过主键删除一场考试
     * ChangeLog : 1. 创建 (2021/5/18 14:53 [zjx]);
     * @param id 主键id
     * @return null
    */
    @ApiOperation("用id删除一场考试")
    @DeleteMapping("deleteOne")
    public ResponseEntity deleteOne(@ApiParam("考试id") Integer id){
        return new ResponseEntity(200,"OK",this.examService.deleteById(id));
    }

    /**
     * Description : 根据考试实体类进行更新
     * ChangeLog : 1. 创建 (2021/5/18 15:00 [zjx]);
     * @param exam  实体类
     * @return null
    */
    @ApiOperation("根据考试类更新一场考试")
    @PutMapping("updateOne")
    public ResponseEntity updateOne(@ApiParam("考试实体类") Exam exam){
        return new ResponseEntity(200,"OK",this.examService.update(exam));
    }



}
